<?php
declare (strict_types = 1);

namespace app\middleware;

use app\BaseController;
use app\Request;
use isszz\sensitive\facade\Sensitive;
use think\response\Json;

class Auth
{
    /**
     * 处理请求
     * @param Request $request
     * @param \Closure $next
     * @return mixed|Json
     */
    public function handle(Request $request, \Closure $next)
    {
		
        $token = $request->header('Authorization')??1;
        $userInfo=check_token($token);

        if ($userInfo['code']==200){
            if (empty($request->param('users_id'))){
                $request->setRoute(['users_id'=>$userInfo['data']['uid']]);
            }
            $request->users_id = $userInfo['data']['uid'];
        }else{
            $request->users_id = 0;
        }
        return $next($request);
    }
}
